<?php
defined('SYS_RUN') or exit();

include_once "source/class.phpmailer.php";

class Mailer extends PHPMailer
{

    private $settings;

    public function __construct() {
        parent::__construct();

        $this->isSMTP();

        $this->settings = Settings::get('mailer');
        if(!count($this->settings))
            throw new Exception('Not found the mailer settings!');

        foreach($this->settings as $settingName => $settingValue) {
            if($settingValue) $this->$settingName = $settingValue;
        }
    }

    public function bodyTemplate($name, $params = array()) {
        $this->isHTML(true);
        $this->Body = Lib::get('template')->render('mails/'.$name, $params, true);
    }

    public function altBodyTemplate($name, $params = array()) {
        $this->isHTML(true);
        $this->AltBody = Lib::get('template')->render('mails/'.$name, $params, true);
    }
}